import 'package:flutter/material.dart';
import 'package:wechat_camera_picker/wechat_camera_picker.dart';

/*
 * 照相机的引擎封装,目前用的 CameraPicker 插件
 */
class CameraEngine {
  /// 拍照
  static Future<AssetEntity?> takePhoto(BuildContext context) async {
    return await CameraPicker.pickFromCamera(
      context,
      pickerConfig: const CameraPickerConfig(
        enableRecording: false,
      ),
    );
  }

  /// 录制视频
  static Future<AssetEntity?> takeVideo(
    BuildContext context, {
    int maxRecordinSeconds = 30,
  }) async {
    return await CameraPicker.pickFromCamera(
      context,
      pickerConfig: CameraPickerConfig(
        enableRecording: true,
        onlyEnableRecording: true,
        enableTapRecording: false,
        enableAudio: true,
        shouldAutoPreviewVideo: true,
        maximumRecordingDuration: Duration(seconds: maxRecordinSeconds),
      ),
    );
  }
}
